local huoshui = fk.CreateSkill{
  name = "lingling__huoshui",
  tags = { Skill.Wake },
}

Fk:loadTranslationTable{
  ["lingling__huoshui"] = "祸水",
  [":lingling__huoshui"] = "觉醒技，游戏开始时，你指定一名其他角色，当其死亡后，删除〖转战〗的“防止之”。",

  ["#lingling__huoshui-choose"] = "祸水：指定一名角色，当其死亡后修改〖转战〗",
  ["@@lingling__huoshui"] = "祸水",
  ["#lingling__wusangui_EasterEgg"] = "丹心已为红颜改，青史难宽白发人。",

  ["$lingling__huoshui1"] = "鼎湖当日弃人间，破敌收京下玉关。",
  ["$lingling__huoshui2"] = "恸哭六军俱缟素，冲冠一怒为红颜。",
}

huoshui:addEffect(fk.Deathed, {
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(huoshui.name) and table.contains(player:getTableMark(huoshui.name), target.id)
  end,
  can_wake = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, "lingling__zhuanzhan", 1)
    room:removeTableMark(player, huoshui.name, target.id)
    if data.killer and data.killer.general == "lingling__lizicheng" and player.general == "lingling__wusangui" then
      room:sendLog{
        type = "#lingling__wusangui_EasterEgg",
        from = player.id,
        toast = true,
      }
      if not data.killer.dead then
        room:damage{
          from = player,
          to = data.killer,
          damage = 1,
          skillName = huoshui.name,
        }
      end
    end
  end,
})

huoshui:addEffect(fk.GameStart, {
  mute = true,
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(huoshui.name) and #player.room:getOtherPlayers(player, false) > 0
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke(huoshui.name)
    room:notifySkillInvoked(player, self.name, "control")
    local to = room:askToChoosePlayers(player, {
      min_num = 1,
      max_num = 1,
      targets = room:getOtherPlayers(player, false),
      skill_name = huoshui.name,
      prompt = "#lingling__huoshui-choose",
      cancelable = false,
    })[1]
    room:setPlayerMark(to, "@@lingling__huoshui", 1)
    room:addTableMark(player, huoshui.name, to.id)
  end,
})

huoshui:addLoseEffect(function (self, player, is_death)
  if player:getMark(huoshui.name) ~= 0 then
    local room = player.room
    for _, p in ipairs(room.alive_players) do
      if table.contains(player:getTableMark(huoshui.name), p.id) and
        not table.find(room:getOtherPlayers(player, false), function (q)
          return table.contains(q:getTableMark(huoshui.name), p.id)
        end) then
        room:setPlayerMark(p, "@@lingling__huoshui", 0)
      end
    end
  end
end)

return huoshui
